#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int binaryS(vector<int> &nums, int target, bool lower)
    {
        int left = 0, right = nums.size() - 1, ans = nums.size();

        while (left <= right)
        {
            int mid = (right + left) >> 1;
            if (nums[mid] > target || (lower && nums[mid] >= target))
            {
                right = mid - 1;
                ans = mid;
            }
            else
            {
                left = mid + 1;
            }
        }
        return ans;
    }

    vector<int> searchRange(vector<int> &nums, int target)
    {
        int right = binaryS(nums, target, false);
        int left = binaryS(nums, target, true);

        if (left <= right && right < nums.size() && nums[left] == target && nums[right] == target)
        {
            return vector<int>{left, right};
        }

        return vector<int>{-1, -1};
    }
};